package com.zpark.controller;

import com.zpark.pojo.Ranking;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: RestTemplateController
 * @Description:
 * @author: RZS
 * @date: 2022/11/8  16:01
 */
@RestController
@RequestMapping("/rest")
public class RestTemplateController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String PATH = "http://user-service/service";

    // 获取所有数据
    @PostMapping("/all.do")
    public List<Ranking> all(){
        return restTemplate.postForObject(PATH + "/all", new ArrayList<Ranking>(), List.class);
    }

    // 根据ID获取数据
    @GetMapping("/get/{id}")
    public Ranking findById(@PathVariable Integer id){
        String url = PATH + "/find_id/" + id;
        System.out.println(url);
        return restTemplate.getForObject(url, Ranking.class);
    }
}
